package com.example.lanou.mynews.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lanou.mynews.R;
import com.example.lanou.mynews.fragment.MainTabMine;
import com.example.lanou.mynews.fragment.MainTabNews;
import com.example.lanou.mynews.fragment.MainTabRead;
import com.example.lanou.mynews.fragment.MainTabTalk;
import com.example.lanou.mynews.fragment.MainTabVideo;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/8.
 */
public class MainFragAdapter extends FragmentPagerAdapter {
    private Context context;
    private ArrayList<Fragment> data;
    private String[]titles={"新闻","阅读","视听","话题","我"};
    private int [] imageview = {R.drawable.tab_news,R.drawable.tab_read,R.drawable.tab_video,R.drawable.tab_talk,R.drawable.tab_mine};
    public MainFragAdapter(FragmentManager fm,Context context) {
        super(fm);
        this.context = context;
        data = new ArrayList<>();
        initData();
    }

    private void initData() {
        data.add(new MainTabNews());
        data.add(new MainTabRead());
        data.add(new MainTabVideo());
        data.add(new MainTabTalk());
        data.add(new MainTabMine());
    }


    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }



    @Override
    public int getCount() {
        return data.size();
    }
    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.main_frag_tab_btn, null);
        TextView textView;
        ImageView imageView;
        textView = (TextView) view.findViewById(R.id.main_frag_tab_tv);
        imageView = (ImageView) view.findViewById(R.id.main_frag_tab_btn_im);
        if (position == 0) {
            view.setSelected(true);
        }
        textView.setText(titles[position]);

        imageView.setImageResource(imageview[position]);
        return view;
    }



}
